declare let eManager;
const {ccclass, property} = cc._decorator;
//2-2 擦脸
@ccclass
export default class CaLian extends cc.Component {
    @property
    stepName = "";
    //擦脸动作 
    @property(cc.Animation)
    caLianAni: cc.Animation = null;

    //粉底消失 
    @property(cc.Animation)
    xiaoShi: cc.Animation = null;

    //白头消失 
    @property(cc.Animation)
    touChuXian: cc.Animation = null;
    
    @property(cc.Node)
    caLianTips: cc.Node = null;

    @property(cc.Node)
    maziNode: cc.Node = null;

    //音效
    @property({type:cc.AudioClip})
    caLian: cc.AudioClip = null;
    
    _isCanPlay = true;
    _audioId = 0;
    start(){
        this.caLianAni.on("finished",this.playFinish,this);
    };

    initData(){
        this._isCanPlay = true;
        this._audioId = 0;
        eManager.emit("REFRESH_STEP_NAME", this.stepName);
        eManager.emit("HZ_REFRESH_ICON_TIPS", null);
    };

    _touchStart(event){
        if(!this._isCanPlay)
            return;
        let state = this.caLianAni.getAnimationState("cuolian");
        if(state){
            if(state.time > 0){
                this.caLianAni.resume();
                this.xiaoShi.resume();
                this.touChuXian.resume();
                cc.audioEngine.resume(this._audioId);
            }else{
                this.caLianAni.play();
                this.xiaoShi.play();
                this.touChuXian.play();
                if (this._audioId > 0) {
                    cc.audioEngine.stop(this._audioId);
                }
                this._audioId =  cc.audioEngine.play(this.caLian, true, 1);
            }
        }
    };

    _touchEnd(event){
        this.caLianAni.pause();
        this.xiaoShi.pause();
        this.touChuXian.pause();
        cc.audioEngine.pause(this._audioId);
    };
   
    playFinish(){
        this._isCanPlay = false;
        this.caLianAni.node.active = false;
        this.caLianTips.active = false;
        this.maziNode.active = false;
        eManager.emit("DONE_POINT", 2);
        eManager.emit("MINI_DONE_STEP");
        eManager.emit("HZ_MAKE_DOT", {
            makeup_close:2,
            makeup_step:this.stepName
        });
    };

}
